import request from '@/utils/request'
let baseUrl = process.env.NODE_ENV === 'production' ? 'api/core' : '/core'

export const getProductList = (data: any) =>
  request({
    baseURL: baseUrl,
    url: '/product/list',
    method: 'post',
    data
  })
// 还款试算
export const tryCalculate = (data: any) =>
  request({
    baseURL: baseUrl,
    url: '/rate/calculate',
    method: 'post',
    data
  })
// 通用字点查询
export const dictOpt = (type: string, data?: any) =>
  // type：add, {term:期次，loanUsage： 借款用途}
  request({
    baseURL: baseUrl,
    url: '/dictionary/' + type,
    method: 'post',
    data
  })
// 增加字点
export const dictAdd = (data?: any) =>
  // {term:期次，loanUsage： 借款用途}
  request({
    baseURL: baseUrl,
    url: '/dictionary/add',
    method: 'post',
    data
  })
// 删除字点查询
export const dictDelete = (id: any) =>
  // type {term:期次，loanUsage： 借款用途}
  request({
    baseURL: baseUrl,
    url: '/dictionary/delete/' + id,
    method: 'post'
  })
export const getProductDetail = (data?: any) =>
  request({
    headers: {
      'Content-type': 'text/plain'
    },
    baseURL: baseUrl,
    url: '/product/query',
    method: 'post',
    data
  })

export const getDetailByProductNo = (data?: any) =>
  request({
    headers: {
      'Content-type': 'text/plain'
    },
    baseURL: baseUrl,
    url: '/product/queryByProNo',
    method: 'post',
    data
  })

export const addProduct = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/product/add',
    method: 'post',
    data
  })

export const updateProduct = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/product/update',
    method: 'post',
    data
  })

export const updateProductStatus = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/product/updateStatus',
    method: 'post',
    data
  })

export const updateProductCheckStatus = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/product/check',
    method: 'post',
    data
  })

export const getOnloadnList = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/asset/onloan/list',
    method: 'post',
    data
  })

export const getFinishList = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/asset/clear/list',
    method: 'post',
    data
  })

export const getOverdueList = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/asset/overdue/list',
    method: 'post',
    data
  })

export const getAccountList = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/account/list',
    method: 'post',
    data
  })

export const getAccountDetail = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/account/query',
    method: 'post',
    data
  })

export const creditGrantingList = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/asset/creditGranting',
    method: 'post',
    data
  })

export const exportCreditGranting = (data?: any) =>
  request({
    responseType: 'blob',
    baseURL: baseUrl,
    url: '/asset/creditGranting/export',
    method: 'post',
    data
  })

export const onloanDownFile = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/asset/onloan/export',
    method: 'post',
    responseType: 'blob',
    data
  })

export const clearDownFile = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/asset/clear/export',
    method: 'post',
    responseType: 'blob',
    data
  })

export const overdueDownFile = (data?: any) =>
  request({
    baseURL: baseUrl,
    url: '/asset/overdue/export',
    method: 'post',
    responseType: 'blob',
    data
  })
// 机构
export const orgApi = {
  uploadFiles: (data: any) =>
    request({
      baseURL: baseUrl,
      url: '/file/upload-files',
      method: 'post',
      data
    }),
  getOrgList: (data: any) =>
    request({
      baseURL: baseUrl,
      url: '/channel/org/channel/list',
      method: 'post',
      data
    }),
  getOrgQuery: (data: any) =>
    request({
      baseURL: baseUrl,
      url: '/channel/org/query',
      method: 'post',
      data
    }),
  getOrgDetail: (data: any) =>
    request({
      baseURL: baseUrl,
      url: `/channel/org/detail/${data.id}`,
      method: 'post',
      data
    }),
  // 创建机构
  createOrg: (data: any) =>
    request({
      baseURL: baseUrl,
      url: '/channel/org/create',
      method: 'post',
      data
    }),

  // 更新机构
  updateOrg: (data: any) =>
    request({
      baseURL: baseUrl,
      url: '/channel/org/update',
      method: 'post',
      data
    })
}
